﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace StudentApartMentManage
{
    public partial class DelAMTInfo : Form
    {
        public DelAMTInfo()
        {
            InitializeComponent();
        }

        private void button3_Click(object sender, EventArgs e)
        {

        }

        private void DelAMTInfo_Load(object sender, EventArgs e)
        {
            dataGridView1.DataSource = DataShow.show("select * from 公寓楼房信息表");
            dataGridView2.DataSource = DataShow.show("select * from 公寓信息表");
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string sql = string.Format("select * from 公寓楼房信息表 where 公寓楼号 like '{0}%'", textBox2.Text.Trim());
            dataGridView1.DataSource = DataShow.show(sql);
            
        }

        private void button3_Click_1(object sender, EventArgs e)
        {
            string sql = string.Format("select * from 公寓信息表 where 公寓号 like '{0}%'", textBox1.Text.Trim());
            dataGridView2.DataSource = DataShow.show(sql);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                string str = dataGridView1.SelectedCells[1].Value.ToString().Trim();
                if (MessageBox.Show("你真的要删除" + str + "楼房的信息吗?", "警告", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    string sql = string.Format("delete from 公寓楼房信息表 where 公寓楼号='{0}'", dataGridView1.SelectedCells[0].Value.ToString());
                    int i = sqlHelper.Execute(sql);
                    if (i != -1)
                    {
                        MessageBox.Show("删除楼房信息成功!");
                        dataGridView1.DataSource = DataShow.show("select * from 公寓楼房信息表");
                    }
                    else
                        MessageBox.Show("删除楼房信息失败!");

                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("删除失败!");
                return;
            }
            

            
        }

        private void button4_Click(object sender, EventArgs e)
        {
            try
            {
                string str = dataGridView1.SelectedCells[0].Value.ToString().Trim();
                if (MessageBox.Show("你真的要删除该宿舍的信息吗?", "警告", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    string sql = string.Format("delete from 公寓信息表 where 公寓号='{0}'", dataGridView2.SelectedCells[0].Value.ToString());
                    int i = sqlHelper.Execute(sql);
                    if (i != -1)
                    {
                        MessageBox.Show("删除宿舍信息成功!");
                        dataGridView2.DataSource = DataShow.show("select * from 公寓信息表");
                    }
                    else
                        MessageBox.Show("删除宿舍信息失败!");

                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("删除失败!");
                return;
            }
        }
    }
}
